<?php
namespace app\index\model;
use think\Model;
use location;
class Login extends Model
{
	//用户登录
	public function index(){
       $data['username'] = trim($_POST['username']);
       $data['password'] =  trim(md5(md5($_POST['password'])));
       $user = db('users')->where($data)->find();
       if($user){
            session('uid',$user['uid']);
			session('username',$user['username']);
			$arr['logintime'] = date('Y-m-d H:i:s');
			$arr['loginnum'] = $user['loginnum']+1;
			$arr['loginip'] = request()->ip();
			$location = new location\IpLocation();
			$ips = $location->getlocation($arr['loginip']);
			$arr['ipadress'] = $ips['country'];
			$arr['session_id'] = session_id();
			$datas = db('users')->where('username',$user['username'])->setField($arr);
			 if($datas){
			 	return 1;
			 }else{
			 	return 602;
			 }
			
       }else{
       	  //用户名或者密码错误
       	  return 605;
       }
	}
}